package com.sxran.im.handler;

import com.sxran.im.bean.MessageReqBody;
import com.sxran.im.controller.ImController;
import com.sxran.im.dao.ImGroupMapper;
import com.sxran.im.info.ImGroup;
import com.sxran.im.info.ImUserGroup;
import com.sxran.im.service.ChatService;
import com.sxran.im.service.UserGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class GetGroupListCmdHandler extends AbstractCmdHandler<MessageReqBody>{
    @Resource
    private ImGroupMapper imGroupMapper;
    @Resource
    private UserGroupService userGroupService;

    @Override
    public Object doBeanService(MessageReqBody json) {
        //
        String userId = ImController.getCurUserId();
        // 群组
        List<ImUserGroup> imUserGroups = userGroupService.selectList(userId);
        //
        List<ImGroup> groups = imUserGroups.stream().map(x -> imGroupMapper.selectById(x.getGid())).collect(Collectors.toList());
        return groups;
    }
}
